<?php
if (isset($_GET['reportID']))
{
	$id = $_GET['reportID'];

	require_once('common/connectdb.php');

	$ConnectDB = new ConnectDB();
	$qReport = "SELECT * FROM tb_reports WHERE report_id='$id'";
	$rReport = $ConnectDB->run_query($qReport);

	if(mysql_num_rows($rReport)!=0)
	{
		echo "<code>0</code>\n<REPORT>";
		//while ($row = mysql_fetch_assoc($rReports))
		$row = mysql_fetch_assoc($rReport);
			echo "\n\t<ID>".$row['report_id']."</ID>";
			echo "\n\t<TITLE>".$row['report_title']."</TITLE>";
			echo "\n\t<DESCRIPTION>".$row['report_description']."</DESCRIPTION>";		
			echo "\n\t<DATE>".$row['report_date']."</DATE>";
			echo "\n\t<COORDINATES>".$row['report_coordinates']."</COORDINATES>";
			echo "\n\t<ADDRESS>".$row['report_address']."</ADDRESS>";
			
			//obtener nombre de usuario
			$user=$row['user_id'];
			$quser = "SELECT * FROM tb_user WHERE user_id='$user'";
			$ruser = $ConnectDB->run_query($quser);
			$rowUser = mysql_fetch_assoc($ruser);
			echo "\n\t<USER>".$rowUser['user_name']."</USER>";
			
			//Obtener tipo de reporte
			$user=$row['reportType_id'];
			$quser = "SELECT * FROM tb_reportType WHERE reportType_id='$user'";
			$ruser = $ConnectDB->run_query($quser);
			$rowUser = mysql_fetch_assoc($ruser);
			echo "\n\t<TYPE>".$rowUser['reportType_description']."</TYPE>";


			//Obtener tipo de reporte

			$qCar = "Select tb_cars.* from tb_cars,report_car  where tb_cars.car_id=report_car.car_id and report_car.report_ID='$id'";
			$rCar = $ConnectDB->run_query($qCar);

			if(mysql_num_rows($rReport)!=0)
			{
				echo "\n\t<CARS>";
				while ($row = mysql_fetch_assoc($rCar))
				{
					echo "\n\t\t<CAR>";
					echo "\n\t\t\t<PLATE>".$row['car_plate']."</PLATE>";
					echo "\n\t\t\t<BRAND>".$row['car_brand']."</BRAND>";
					echo "\n\t\t\t<MODEL>".$row['car_model']."</MODEL>";		
					echo "\n\t\t\t<YEAR>".$row['car_year']."</YEAR>";
					echo "\n\t\t\t<COLOR>".$row['car_color']."</COLOR>";
					echo "\n\t\t\t<DRIVER>".$row['carDriver_name']."</DRIVER>";
					echo "\n\t\t\t<DRIVERID>".$row['carDriver_id']."</DATE>";
					echo "\n\t\t</CAR>";
				}
				echo "\n\t</CARS>";
			}


		echo"\n</REPORT>";
	} 
	else {
		echo "<code>1</code>";
	}
} else {
	echo "<code>1</code>";
}
?>
